<?php
$id=$_POST['id'];
$spid=$_POST['spid']; 
$return_msg=$_POST['return_msg']; 
$ddusername=$_POST['ddusername'];
$fangshi=$_POST['fangshi'];
$spend=$_POST['spend'];
$sj= date("Y-m-d H:i:s");  

$sql="update ".$BIAOTOU."dhdingdan set return_msg='".$return_msg."',status=2 where id=".$id.' limit 1';
$rs = mysql_query($sql);

$sql="update ".$BIAOTOU."user set dhstate=0 where ddusername='".$ddusername."' limit 1";
$rs = mysql_query($sql);

if($fangshi==1){
    ///现金减少
    $sql="update ".$BIAOTOU."user set money=money+".$spend.",dhstate=0 where ddusername='".$ddusername."' limit 1";
    $rs = mysql_query($sql);
	
	///发送明细
    $q = "insert into ".$BIAOTOU."mingxi (ddusername,shijian,je,jifen,addtime,memo) values('".$ddusername."','兑换失败','".$spend."',0,'".$sj."','您的商品兑换申请被退回')";
    mysql_query($q);
}
elseif($fangshi==2){
    ///积分减少
    $sql="update ".$BIAOTOU."user set jifen=jifen+".$spend.",dhstate=0 where ddusername='".$ddusername."' limit 1";
    $rs = mysql_query($sql);
	
	///发送明细
    $q = "insert into ".$BIAOTOU."mingxi (ddusername,shijian,je,jifen,addtime,memo) values('".$ddusername."','兑换失败',0,'".$spend."','".$sj."','您的商品兑换申请被退回')";
    mysql_query($q);
}


///发送站内信
$q = "insert into ".$BIAOTOU."msg (ddusername,title,see,addtime,senduser,content) values('".$ddusername."','兑换失败','0','".$sj."','网站客服','".$return_msg."')";
mysql_query($q);
///增加商品数量
$q = "update ".$BIAOTOU."dhlist set num=num+1 where id='".$spid."' limit 1";
mysql_query($q);
admin_log('退回商品兑换');
alert('兑换退回成功','admin.php?act=duihuan_list');
?>